﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using TMIS.DAL;

namespace TMIS.BLL
{
    public class Angecy
    {
        #region 添加数据前数据重复验证功能定义与实现
        #region 验证院系信息是否重复
        private bool CheckDepartment(string department)
        {
            DAL.Department dal = DALFactory.DALFactory.CreateDepartment();
            if (dal.Search(department) == Guid.Empty)
            {
                return true;
            }
            else
                return false;
        }
        #endregion

        #region 验证专业信息是否重复
        private bool CheckProfession(string profession)
        {
            DAL.Profession dal = DALFactory.DALFactory.CreateProfession();
            if (dal.Search(profession) == Guid.Empty)
            {
                return true;
            }
            else
                return false;
        }
        #endregion

        #region 验证年级信息是否重复
        private bool CheckGrade(string profession,Guid professionGuid)
        {
            DAL.Grade dal = DALFactory.DALFactory.CreateGrade();
            if (dal.Search(profession,professionGuid) == Guid.Empty)
            {
                return true;
            }
            else
                return false;
        }
        #endregion

        #region 验证班级信息是否重复
        private bool CheckClass(string classes, Guid GradeGuid)
        {
            DAL.Classes dal = DALFactory.DALFactory.CreateClass();
            if (dal.Search(classes, GradeGuid) == Guid.Empty)
            {
                return true;
            }
            else
                return false;
        }
        #endregion

        #endregion

        #region 添加数据信息相关功能定义与实现
        #region 添加院系信息相关功能定义与实现
        public bool InsertDepartment(string department)
        {
            if (CheckDepartment(department))
            {
                Model.Department dep = new Model.Department()
                {
                    ID = Guid.NewGuid(),
                    Name = department
                };
                Department dal = DALFactory.DALFactory.CreateDepartment();
                dal.Insert(dep);
                return true;
            }
            else
                return false;
            
        }
        #endregion

        #region 添加专业信息相关功能定义与实现
        public bool InsertProfession(string profession,Guid departmentGuid)
        {
            if (CheckProfession(profession))
            {
                Model.Profession pro = new Model.Profession()
                {
                    ID = Guid.NewGuid(),
                    Name = profession,
                    DepartmentID = departmentGuid
                };
                Profession dal = DALFactory.DALFactory.CreateProfession();
                dal.Insert(pro);
                return true;
            }
            else 
                return false;
        }
        #endregion

        #region 添加年级信息相关功能定义与实现
        public bool InsertGrade(string grade,string simply, Guid professionGuid)
        {
            if (CheckGrade(grade, professionGuid))
            {
                Model.Grade gra = new Model.Grade
                {
                    ID = Guid.NewGuid(),
                    Name = grade,
                    Simple=simply,
                    ProfessionID = professionGuid
                };
                Model.Summary sum = new Model.Summary
                {
                    ID=gra.ID
                };
                DAL.Grade dal = DALFactory.DALFactory.CreateGrade();
                dal.Insert(gra);
                DAL.Summary sdal = DALFactory.DALFactory.CreateSummary();
                sdal.Add(sum);
                return true;
            }
            else
                return false;
        }
        #endregion

        #region 添加班级信息相关功能定义与实现
        public bool InsertClass(string classes, Guid gradeGuid)
        {
            if (CheckClass(classes, gradeGuid))
            {
                Model.Class cla = new Model.Class()
                {
                    ID = Guid.NewGuid(),
                    Name = classes,
                    GradeID = gradeGuid
                };
                Classes dal = DALFactory.DALFactory.CreateClass();
                dal.Insert(cla);
                return true;
            }
            else
                return false;
        }
        #endregion
        #endregion

        #region 查找数据信息相关功能定义与实现
        #region 查找院系信息相关功能定义与实现
        /// <summary>
        /// 获得所有院系名称
        /// </summary>
        /// <returns></returns>
        public string[] SearchDepartment()
        {
            Department dal = DALFactory.DALFactory.CreateDepartment();
            return dal.Search();
            
        }

        /// <summary>
        /// 获得院系名称对应的ID号
        /// </summary>
        /// <param name="department">院系名称</param>
        /// <returns></returns>
        public Guid SearchDepartment(string department)
        {
            Department dal=DALFactory.DALFactory.CreateDepartment();
            Guid guid = dal.Search(department);
            return guid;
        }
        #endregion

        #region 查找专业信息相关功能定义与实现
        /// <summary>
        /// 获得所有专业名称
        /// </summary>
        /// <returns></returns>
        public string[] SearchProfession()
        {
            Profession dal = DALFactory.DALFactory.CreateProfession();
            return dal.Search();
        }
        /// <summary>
        /// 获得专业名称对应的ID号
        /// </summary>
        /// <param name="department">专业名称</param>
        /// <returns></returns>
        public Guid SearchProfession(string profession)
        {
            Profession dal = DALFactory.DALFactory.CreateProfession();
            return dal.Search(profession);
        }
        #endregion

        #region 查找年级信息相关功能定义与实现
        /// <summary>
        /// 获得所有年级名称
        /// </summary>
        /// <returns></returns>
        public string[] SearchGrade()
        {
            Grade dal = DALFactory.DALFactory.CreateGrade();
            return dal.Search();
        }
        /// <summary>
        /// 获得年级名称对应的ID号
        /// </summary>
        /// <param name="department">年级名称</param>
        /// <returns></returns>
        public Guid SearchGrade(string grade)
        {
            Grade dal = DALFactory.DALFactory.CreateGrade();
            return dal.Search(grade);
        }
        #endregion

        #region 查找班级信息相关功能定义与实现
        /// <summary>
        /// 获得所有班级名称
        /// </summary>
        /// <returns></returns>
        public string[] SearchClass()
        {
            Classes dal = DALFactory.DALFactory.CreateClass();
            return dal.Search();
        }
        /// <summary>
        /// 获得班级名称对应的ID号
        /// </summary>
        /// <param name="department">班级名称</param>
        /// <returns></returns>
        public Guid SearchClass(string classes)
        {
            Classes dal = DALFactory.DALFactory.CreateClass();
            return dal.Search(classes);
        }
        #endregion
        #endregion
    }
}
